/** 
 * DefaultScoreCardFactory.java Created by iweerarathna on Aug 30, 2011.
 * 
 * Copyright (c) 2011 Virtusa Corporation. All Rights Reserved.<br><br>. 
 * 
 */
package org.uim.cricket.analyzer.parsers;

import org.uim.cricket.analyzer.parsers.aggr.impl.SingleInningParser;
import org.uim.cricket.analyzer.parsers.batting.impl.*;
import org.uim.cricket.analyzer.parsers.bowling.impl.*;
import org.uim.cricket.analyzer.parsers.inning.impl.*;
import org.uim.cricket.analyzer.parsers.match.CricketMatchParsable;
import org.uim.cricket.analyzer.parsers.match.impl.*;
import org.uim.cricket.analyzer.parsers.misc.*;
import org.uim.cricket.analyzer.parsers.misc.impl.*;
import org.uim.cricket.analyzer.parsers.partnerships.impl.*;

/**
 * TODO Class description goes here.
 * @version 
 * @author iweerarathna
 */
public class DefaultScoreCardFactory extends AbstractScoreCardFactory {

    @Override
    public CricketMatchParsable createScoreCardParser(String type) throws Exception {
        if (type.equalsIgnoreCase("default")) {
            return this.defaultSet();
        }
        throw new Exception("Unknown scorecard parser type '" + type + "'!");
    }

    protected CricketMatchParsable defaultSet() {
        URLIDParsable urlIDParser = new NoChangeURLIDParser();
        URLTitleParsable urlTitleParser = new DefaultURLTitleParser();
        SimpleNameParsable simpleNameParse = new OneOrTwoSimpleNameParser();
        
        SingleInningParser innParser = new SingleInningParser(new DefaultInningExtrasParser(), new DefaultInningTotalsParser());
        
        DefaultBattingInningParser batinnParser = new DefaultBattingInningParser(new DefaultOutDetailsParser(), urlIDParser, urlTitleParser);
        BattingInningsParser allBatInnsParser = new BattingInningsParser(batinnParser, new DefaultInningHeaderLabelParser());
        
        DefaultBowlingInningParser bowlinnParser = new DefaultBowlingInningParser(urlIDParser, urlTitleParser);
        BowlingInningsParser allBowlInnsParser = new BowlingInningsParser(bowlinnParser);
        
        DefaultFallOfWicketParser fowParser = new DefaultFallOfWicketParser();
        FallOfWicketsParser fowsParser = new FallOfWicketsParser(fowParser);
        
        innParser.setAbsBatsParser(allBatInnsParser);
        innParser.setAbsBowlParser(allBowlInnsParser);
        innParser.setAbsFowParser(fowsParser);
        innParser.setDnbParser(new DefaultDidNotBatParser(urlIDParser, urlTitleParser));
        
        DefaultCricketMatchParser cmparsable = new DefaultCricketMatchParser();
        cmparsable.setDateParser(new DefaultMatchDatesParser( new DefaultMatchSpanParser()));
        cmparsable.setGroundParser(new DefaultGroundParser(urlIDParser));
        cmparsable.setIdParser(new DefaultMatchIDParser());
        cmparsable.setResultParser(new DefaultMatchResultParser());
        cmparsable.setDebutParser(new DefaultDebutsParser());
        cmparsable.setSingleInnParser(innParser);
        cmparsable.setSeriesParser(new DefaultMatchSeriesParser(urlIDParser));
        cmparsable.setSimpleNameParser(simpleNameParse);
        cmparsable.setSeriesResultParser(new DefaultSeriesResultParser());
        cmparsable.setOfficialParser(new DefaultMatchOfficialParser(urlIDParser, urlTitleParser, simpleNameParse));
        cmparsable.setTossParser(new DefaultTossParser());
        
        return cmparsable;
    }
    
}
